package com.java.comprehensive.arithmetic.leecode.easy;

import util.TreeNode;

import java.util.List;

/**
 * @Author: Dgg
 * @Date: 2021/11/29 20:41
 * 相同的树
 */
public class LeetCode_100 {
	/** 其实时循环当前 两个集合指针是一样的 先比自己相等null 就是true  然后在比不一样的话就是flase 在比value */
	public static boolean isSameTree(TreeNode p, TreeNode q) {
		if (p == null && q == null) {
			return true;
		} else if (p == null || q == null) {
			return false;
		} else if (p.val != q.val) {
			return false;
		} else {
			return isSameTree(p.left, q.left) && isSameTree(p.right, q.right);
		}
	}

	public static void getTreeNode(TreeNode node, List<Integer> integers) {
		if (node == null) {
			integers.add(0);
			return;
		}
		integers.add(node.val);
		getTreeNode(node.left, integers);
		getTreeNode(node.right, integers);

	}

	public static void main(String[] args) {
		TreeNode treeNode2 = new TreeNode(2, new TreeNode(3, null, null), null);
		TreeNode treeNode = new TreeNode(1, null, treeNode2);
		isSameTree(treeNode, treeNode);
	}
}
